<%@ page contentType="text/html;charset=UTF-8" %>
<%@ page import="org.apache.shiro.web.filter.authc.FormAuthenticationFilter" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<html>
<head>
    <title>${fns:getConfig('productName')} 登录</title>
    <meta name="decorator" content="blank"/>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <!-- ace styles -->
    <link rel="stylesheet" href="/static/common/login/ace.css">
    <link rel="stylesheet" href="/static/common/login/ace-rtl.css">

    <style type="text/css">

        .bound {
            background-color: white;
            border-radius: 4px;
        }

        input {
            width: 100%;
        }

        .bg-white {
            background: #fff;
        }
    </style>

    <script>
        if (window.top !== window.self) {
            window.top.location = window.location;
        }
    </script>
    <script type="text/javascript">
        $(document).ready(function () {

            $("body").addClass("login-layout light-login");
            $("body").css("background", "#fff");

            $("#loginForm").validate({
                rules: {
                    validateCode: {remote: "/servlet/validateCodeServlet"}
                },
                messages: {
                    username: {required: "请填写用户名."}, password: {required: "请填写密码."},
                    validateCode: {remote: "验证码不正确.", required: "请填写验证码."}
                },
                errorLabelContainer: "#messageBox",
                errorPlacement: function (error, element) {
                    error.appendTo($("#loginError").parent());
                }
            });
        });
        // 如果在框架或在对话框中，则弹出提示并跳转到首页
        if (self.frameElement && self.frameElement.tagName == "IFRAME" || $('#left').length > 0 || $('.jbox').length > 0) {
            alert('未登录或登录超时。请重新登录，谢谢！');
            top.location = "${ctx}";
        }
    </script>
    <script type="text/javascript">
        $(document).ready(function () {

            /**
             * 注册用户验证
             */
            $("#regForm").validate({
                rules: {
                    mobile: {remote: "${ctx}/sys/user/validateMobile"},
                    randomCode: {
                        remote: {
                            url: "${ctx}/sys/register/validateMobileCode",
                            data: {
                                mobile: function () {
                                    return $("#mobile").val();
                                }
                            }
                        }
                    }
                },
                messages: {
                    loginPass: {required: "密码不能为空."},
                    confirmNewPassword: {equalTo: "输入与上面相同的密码"},
                    ck1: {required: "必须接受用户协议."},
                    companyName: {required: "公司名称不能为空."},
                    mobile: {remote: "此手机号已经被注册!", required: "手机号不能为空."},
                    randomCode: {remote: "验证码不正确!", required: "验证码不能为空."}
                },
                submitHandler: function (form) {
                    loading('正在提交，请稍等...');
                    form.submit();
                },
                errorContainer: "#messageBox",
                errorPlacement: function (error, element) {
                    $("#messageBox").text("输入有误，请先更正。");
                    if (element.is(":checkbox") || element.is(":radio") || element.parent().is(".input-append")) {
                        error.appendTo(element.parent().parent());
                    } else {
                        error.insertAfter(element);
                    }
                }
            });

            /**
             * 忘记密码验证
             */
            $("#resetForm").validate({
                rules: {
                    mobile: {remote: "${ctx}/sys/user/validateMobileExist"}
                },
                messages: {
                    mobile: {remote: "此手机号未注册!", required: "手机号不能为空."}
                },
                submitHandler: function (form) {
                    loading('正在提交，请稍等...');
                    form.submit();
                },
                errorContainer: "#messageBox",
                errorPlacement: function (error, element) {
                    $("#messageBox").text("输入有误，请先更正。");
                    if (element.is(":checkbox") || element.is(":radio") || element.parent().is(".input-append")) {
                        error.appendTo(element.parent().parent());
                    } else {
                        error.insertAfter(element);
                    }
                }
            });
            // 手机号码验证
            jQuery.validator.addMethod("isMobile", function (value, element) {
                var length = value.length;
                var mobile = /^(13[0-9]{9})|(18[0-9]{9})|(14[0-9]{9})|(17[0-9]{9})|(15[0-9]{9})$/;
                return (length == 11 && mobile.test(value));
            }, "请正确填写您的手机号码");


            $('#sendPassBtn').click(function () {
                if ($("#tel_resetpass").val() == "" || $("#tel_resetpass-error").text() != "") {
                    top.layer.alert("请输入有效的注册手机号码！", {icon: 0});//讨厌的白色字体问题
                    return;

                }
                $("#sendPassBtn").attr("disabled", true);
                $.get("${ctx}/sys/user/resetPassword?mobile=" + $("#tel_resetpass").val(), function (data) {
                    if (data.success == false) {
                        top.layer.alert(data.msg, {icon: 0});//讨厌的白色字体问题
                        //alert(data.msg);
                        $("#sendPassBtn").html("重新发送").removeAttr("disabled");
                        clearInterval(countdown);

                    }

                });
                var count = 60;
                var countdown = setInterval(CountDown, 1000);

                function CountDown() {
                    $("#sendPassBtn").attr("disabled", true);
                    $("#sendPassBtn").html("等待 " + count + "秒!");
                    if (count == 0) {
                        $("#sendPassBtn").html("重新发送").removeAttr("disabled");
                        clearInterval(countdown);
                    }
                    count--;
                }


            });


            $('#sendCodeBtn').click(function () {
                if ($("#mobile").val() == "" || $("#tel-error").text() != "") {
                    top.layer.alert("请输入有效的注册手机号码！", {icon: 0});//讨厌的白色字体问题
                    return;

                }
                $("#sendCodeBtn").attr("disabled", true);
                $.get("${ctx}/sys/register/getRegisterCode?mobile=" + $("#mobile").val(), function (data) {
                    if (data.success == false) {
                        //top.layer.alert(data.msg, {icon: 0});讨厌的白色字体问题
                        alert(data.msg);
                        $("#sendCodeBtn").html("重新发送").removeAttr("disabled");
                        clearInterval(countdown);

                    }

                });
                var count = 300;
                var countdown = setInterval(CountDown, 1000);

                function CountDown() {
                    $("#sendCodeBtn").attr("disabled", true);
                    $("#sendCodeBtn").html("等待 " + count + "秒!");
                    if (count == 0) {
                        $("#sendCodeBtn").html("重新发送").removeAttr("disabled");
                        clearInterval(countdown);
                    }
                    count--;
                }


            });

        });
    </script>
</head>


<body class="login-layout light-login" style="background: #fff;">

<div class="main-container">
    <div class="main-content">
        <div class="row">
            <div class="col-sm-10 col-sm-offset-1">
                <div class="login-container">

                    <div class="center">
                        <h2 class="">
                            <br>
                            ${fns:getConfig('productName')}
                            <br>
                        </h2>

                        <!-- 0:隐藏tip, 1隐藏box,不设置显示全部 -->

                        <script type="text/javascript">top.$.jBox.closeTip();</script>

                    </div>

                    <div class="space-6"></div>

                    <div class="position-relative">
                        <div id="login-box" class="login-box visible widget-box no-border bound"
                             style="-webkit-box-shadow: 0 0 8px 6px rgba(0, 0, 0, 0.12);background-color: #fafafa;border-bottom: #fafafa;">
                            <div class="widget-body bound">
                                <div class="widget-main bound">
                                    <h4 class="header blue lighter bigger">
                                        <i class="ace-icon fa fa-lock green"></i>
                                        用户登录
                                    </h4>

                                    <div class="space-6"></div>

                        <form id="loginForm" class="form-signin" action="${ctx}/login" method="post" novalidate="novalidate">
                            <fieldset>
                                <label class="block clearfix">
                                    <span class="block input-icon input-icon-right">
                                        <input type="text" id="username" name="username"
                                               class="form-control required error" value="${username}"
                                               placeholder="用户名" aria-required="true"
                                               aria-invalid="true">
                                        <i class="ace-icon fa fa-user"></i>
                                    </span>
                                </label>

                                <label class="block clearfix">
                                    <span class="block input-icon input-icon-right">
                                        <input type="password" id="password" name="password"
                                               value="admin" class="form-control required valid"
                                               placeholder="密码" aria-required="true"
                                               aria-invalid="false">
                                        <i class="ace-icon fa fa-lock"></i>
                                    </span>
                                </label>

                                <c:if test="${isValidateCodeLogin}">
                                    <div class="validateCode">
                                        <label class="input-label mid" for="validateCode">验证码</label>
                                        <sys:validateCode name="validateCode" inputCssStyle="margin-bottom:0;"/>
                                    </div>
                                </c:if>

                                <div class="space"></div>

                                <div class="clearfix">
                                    <label class="inline">
                                        <input type="checkbox" id="rememberMe" name="rememberMe" class="ace" ${rememberMe ? 'checked' : ''}>
                                        <span class="lbl"> 记住我（公共场所慎用）</span>
                                    </label>

                                    <button type="submit"
                                            class="width-100 pull-right btn btn-sm btn-primary">
                                        <i class="ace-icon fa fa-key"></i>
                                        <span class="bigger-110">登录</span>
                                    </button>
                                </div>

                            </fieldset>
                        </form>

                                    <br>
                                    <br>
                                    <div class="form-options clearfix">
                                        <div>
                                            <a href="#" data-target="#forgot-box" class="pull-left">
                                                <font color=" #007aff;"><i class="ace-icon fa fa-arrow-left"></i>
                                                    忘记密码</font>
                                            </a>
                                        </div>

                                        <%--<div>--%>
                                            <%--<a href="#" data-target="#signup-box" class="pull-right user-signup-link">--%>
                                                <%--<font color=" #A73438">没有账号？注册--%>
                                                    <%--<i class="ace-icon fa fa-arrow-right"></i></font>--%>
                                            <%--</a>--%>
                                        <%--</div>--%>
                                    </div>
                                </div><!-- /.widget-main -->


                            </div><!-- /.widget-body -->
                        </div><!-- /.login-box -->

                        <div id="forgot-box" class="forgot-box widget-box no-border bound">
                            <div class="widget-body bound">
                                <div class="widget-main bound">
                                    <h4 class="header red lighter bigger">
                                        <i class="ace-icon fa fa-key"></i>
                                        找回密码
                                    </h4>

                                    <div class="space-6"></div>
                                    <p>
                                        请输入您的注册手机号，您将会收到新的密码。
                                    </p>

                                    <form id="resetForm" novalidate="novalidate">
                                        <fieldset>
                                            <label class="block clearfix">
														<span class="block input-icon input-icon-right">
															<input id="tel_resetpass" name="tel_resetpass" type="tel"
                                                                   class="form-control  text-muted required isMobile"
                                                                   placeholder="请输入手机号" aria-required="true">
															<i class="ace-icon fa fa-phone"></i>
														</span>
                                            </label>

                                            <div class="clearfix">
                                                <button id="sendPassBtn" type="button"
                                                        class="width-35 pull-right btn btn-sm btn-danger">
                                                    <i class="ace-icon fa fa-share"></i>
                                                    <span class="bigger-110">发送!</span>
                                                </button>
                                            </div>
                                        </fieldset>
                                    </form>
                                    <div class="form-options center">
                                        <br>
                                        <br>
                                        <a href="#" data-target="#login-box" class="">
                                            <font color=" #A73438"><i class="ace-icon fa fa-arrow-left"></i>
                                                返回登录
                                            </font>
                                        </a>
                                    </div>
                                </div><!-- /.widget-main -->

                            </div><!-- /.widget-body -->
                        </div><!-- /.forgot-box -->

                        <div id="signup-box" class="signup-box widget-box no-border bound">
                            <div class="widget-body bound">
                                <div class="widget-main bound">
                                    <h4 class="header green lighter bigger">
                                        <i class="ace-icon fa fa-users blue"></i>
                                        用户注册
                                    </h4>

                                    <div class="space-6"></div>

                                    <form id="regForm" action="${ctx}/sys/register/registerUser" method="post"
                                          class="form-group form-horizontal" novalidate="novalidate">
                                        <fieldset>
                                            <label class="block clearfix">
														<span class="block input-icon input-icon-right">
															<input id="mobile" name="mobile" type="text" value=""
                                                                   maxlength="11" minlength="11"
                                                                   class="form-control text-muted required isMobile"
                                                                   placeholder="手机号" aria-required="true">
															<i class="ace-icon fa fa-phone"></i>
														</span>
                                            </label>
                                            <label class="block clearfix">
														<span class="block input-icon input-icon-right">
															<input id="randomCode" name="randomCode" type="text"
                                                                   value="" maxlength="4" minlength="4" class="required"
                                                                   placeholder="验证码" style="width: 180px;"
                                                                   aria-required="true">
															<button class="width-38 pull-right btn btn-sm btn-primary"
                                                                    type="button" id="sendCodeBtn">
																<i class="ace-icon fa fa-share"></i>
																<span class="bigger-100">获取验证码!</span>
															</button>
															<label id="code-error" class="error" for="code"
                                                                   style="display:none"></label>
														</span>
                                            </label>
                                            <label class="block clearfix">
														<span class="block input-icon input-icon-right">
															<input id="companyName" name="companyName" type="text"
                                                                   value="" maxlength="20" minlength="3"
                                                                   class="form-control required" placeholder="公司名称"
                                                                   aria-required="true">
															<i class="ace-icon fa fa-user"></i>
														</span>
                                            </label>

                                            <label class="block clearfix">
														<span class="block input-icon input-icon-right">
															<input id="loginPass" name="loginPass" type="password"
                                                                   value="" maxlength="20" minlength="3"
                                                                   class="form-control required" placeholder="密码"
                                                                   aria-required="true">
															<i class="ace-icon fa fa-lock"></i>
														</span>
                                            </label>

                                            <label class="block clearfix">
														<span class="block input-icon input-icon-right">
															<input id="confirmNewPassword" name="confirmNewPassword"
                                                                   type="password" value="" maxlength="20" minlength="3"
                                                                   class="form-control required" equalto="#loginPass"
                                                                   placeholder="重复密码" aria-required="true">
															<i class="ace-icon fa fa-retweet"></i>
														</span>
                                            </label>

                                            <label class="block">
                                                <input name="ck1" type="checkbox" class="required ace"
                                                       aria-required="true">
                                                <span class="lbl">
															我接受
															<a href="${ctx}/sys/register/agree"
                                                               target="_blank">《用户注册协议》</a>
														</span>
                                                <label id="ck1-error" class="error" for="ck1" style="display: none;">必须接受用户协议</label>
                                            </label>

                                            <div class="space-24"></div>

                                            <div class="clearfix">
                                                <button type="reset" class="width-30 pull-left btn btn-sm">
                                                    <i class="ace-icon fa fa-refresh"></i>
                                                    <span class="bigger-110">重置</span>
                                                </button>

                                                <button type="submit"
                                                        class="width-65 pull-right btn btn-sm btn-success">
                                                    <span class="bigger-110">注册</span>

                                                    <i class="ace-icon fa fa-arrow-right icon-on-right"></i>
                                                </button>
                                            </div>
                                        </fieldset>
                                    </form>
                                    <div class="form-options center">
                                        <br>
                                        <br>
                                        <a href="#" data-target="#login-box" class="">
                                            <font color=" #A73438"><i class="ace-icon fa fa-arrow-left"></i>
                                                返回登录
                                            </font>
                                        </a>
                                    </div>
                                </div>


                            </div><!-- /.widget-body -->
                        </div><!-- /.signup-box -->
                    </div><!-- /.position-relative -->

                    <%--<div class="center"><h4 id="id-company-text"><font color="#8a8a8a">© http://www.javafast.cn</font></h4></div>--%>

                    <div class="center">
                        <h7 id="id-company-text">
                            &copy; 2016-${fns:getConfig('copyrightYear')} <a
                            href="${pageContext.request.contextPath}${fns:getFrontPath()}">${fns:getConfig('productName')}</a>

                            - Powered By
                        <a href="http://jeesite.com" target="_blank">vivo</a> ${fns:getConfig('version')}
                        </h7>
                    </div>



                </div>
            </div><!-- /.col -->
        </div><!-- /.row -->
    </div><!-- /.main-content -->
</div><!-- /.main-container -->

<!-- basic scripts -->

<!--[if !IE]> -->
<script type="text/javascript">
    window.jQuery || document.write("<script src='../assets/js/jquery.js'>" + "<" + "/script>");
</script>

<!-- <![endif]-->

<!--[if IE]>
<script type="text/javascript">
    window.jQuery || document.write("<script src='../assets/js/jquery1x.js'>" + "<" + "/script>");
</script>
<![endif]-->

<script type="text/javascript">
    if ('ontouchstart' in document.documentElement) document.write("<script src='../assets/js/jquery.mobile.custom.js'>" + "<" + "/script>");
</script>
<style>
    /* Validation */

    label.error {
        color: #cc5965;
        display: inline-block;
        margin-left: 5px;
    }

    .form-control.error {
        border: 1px dotted #cc5965;
    }
</style>
<!-- inline scripts related to this page -->
<script type="text/javascript">
    $(document).ready(function () {
        $(document).on('click', '.form-options a[data-target]', function (e) {
            e.preventDefault();
            var target = $(this).data('target');
            $('.widget-box.visible').removeClass('visible');//hide others
            $(target).addClass('visible');//show target
        });
    });


</script>


</body>
</html>